<?php
	//simple functions for videos...

	function videos_list() {
		global $db;
		$result = $db->query('SELECT * from VIDEOS order by CREATED desc limit 10;');
		
		while($row=$result->fetch(SQLITE_ASSOC)) {

		    // fetch current row

		    $name = $row['name'];
		    $id = $row['id']; 
		    $filename = $row['filename'];
		    $description = $row['description'];
		    $processed = $row['processed'];

		    //simple HTML5 to render our video
		    echo('<div class="video">');
			echo('<span class="title">'.$row->name."</span><br/>");
		
			if(processed) {	
				echo("<video id=\"video-$id\" controls=\"\" src=\"media/transcoded/$filename\">
				<p>Your web browser doesn't support HTML5 video</p>
				</video>");
			} else {
				echo("This video is currently processing. It will be available soon.");
			}
			echo("<div class=\"description\">".$description."</div></div>");

		}
	}

	function video_insert($filename) {
		global $db;
		$esc_filename=sqlite_escape_string($filename);
		$result = $db->query("INSERT INTO VIDEOS (id, name, filename, created) VALUES (NULL, '$esc_filename', '$esc_filename', DATETIME('now'));");
		
	}
